package com.api.gbhg.zengping.dao;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import weaver.conn.RecordSet;

import java.util.Map;

/**
 * @program: gbhg-oa
 * @author: Mr.zeng
 * @create: 2021-01-18 14:16
 **/
public class LeadingPortalsDao {
    public static final Logger LOGGER = LoggerFactory.getLogger("gbhg");

    /**
     * 领导门户=============查询重点项目
     * @param map
     * @return
     */
    public RecordSet selectKeyProjectList(Map<String,Object> map){
        RecordSet rs=new RecordSet();
        String sql="select lcjlsqjlid AS requestId,xmmin,sbdw,yszje from uf_jingfei_version where sfzdxm=1 and ysnd=? and sbdw=?";
        StringBuffer sb=new StringBuffer();
        sb.append(sql);
        int pageNum= (int) map.get("pageNum");
        int pageSize= (int) map.get("pageSize");
        pageNum=(pageNum-1)*pageSize;
        // 判断是mysql 还是sqlserver
        if("sqlserver".equals(rs.getDBType())){
            sb.append(" order by lcjlsqjlid offset "+pageNum+" rows fetch next "+pageSize+" rows only");
        }else if("mysql".equals(rs.getDBType())){
            sb.append(" LIMIT "+pageNum+","+pageSize+"");
        }
        LOGGER.info("领导门户-重点项目列表查询sql：--------->"+sb);
        rs.executeQuery(sb.toString(),map.get("ysnd"),map.get("sbdw"));
        return rs;
    }

    /**
     * 领导门户------查询重点项目条数
     * @param map
     * @return
     */
    public RecordSet selectKeyProjectCount(Map<String,Object> map){
        RecordSet rs=new RecordSet();
        String sql="select count(1)num from uf_jingfei_version where sfzdxm=1 and ysnd=? and sbdw=?";
        rs.executeQuery(sql,map.get("ysnd"),map.get("sbdw"));
        LOGGER.info("领导门户-重点项目列表查询条数sql:------->"+sql);
        return rs;
    }


    /**
     * 查询经费表 剩余额度
     * @param requestId
     * @return
     */
    public RecordSet queryExecuteRate(String requestId){
        RecordSet rs=new RecordSet();
        String sql="select sum(syed)syed from uf_jingfei where requestId=?";
        LOGGER.info("requestId查询经费表剩余额度sql:------------->"+sql);
        rs.executeQuery(sql,requestId);
        return rs;
    }

    /**
     * 中央财政拨款
     * @param ysly
     * @param param
     * @return
     */
    public RecordSet queryCentralFinanceAppropriation(int ysly,Map<String,Object> param){
        RecordSet rs=new RecordSet();
        String sql="select sum(je)je,sum(syed)syed from uf_jingfeilaiyuan where ysly="+ysly+" and nd="+param.get("nd")+" and sbdw in("+param.get("sbdw")+")";
        LOGGER.info("中央财政拨款查询sql--------->"+sql);
        rs.executeQuery(sql);
        return rs;
    }


    /**
     * 根据当前用户返回上级分部
     * @param userId
     * @return
     */
    public RecordSet selectCurrentUserReturnSubcompany(int userId){
        RecordSet rs=new RecordSet();
        String sql="select  d.subcompanyid1  from hrmResource h,HrmDepartment d,HrmSubCompany s where h.departmentid=d.id and h.subcompanyid1=s.id and h.id="+userId;
//        String sql="select * from HrmSubCompany where id=(select d.subcompanyid1 from HrmDepartment d,hrmResource h where h.departmentid=d.id and h.id="+userId+")";
        rs.executeQuery(sql);
        return rs;
    }
}
